<template>
	<hyb-page title="商家中心">
		<!-- 请开始您的开发 ~ -->
		<template v-slot:body>
			<view>
				<view class="gui-list" :style="{'background':base.qjcolor}">
					<view style="height: 40rpx;"></view>
					<view class="gui-flex gui-justify-content-end gui-padding-x">
						<view @tap="location()" class="gui-color-white"><text class="gui-icons"
								style="font-size: 50rpx;">&#xe61c;</text>
						</view>
					</view>
					<view class="gui-padding-middle gui-list-items" style="height: 145rpx;">
						<!-- #ifdef MP -->
						<button class="avatar-wrapper" style="width: 120rpx;height: 120rpx;border-radius: 50%;"
							open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar">
							<image style="width: 120rpx;height: 120rpx;border-radius: 50%;"
								:src="info.s_thumb?info.s_thumb:base.erweima" mode="scaleToFill">
							</image>
						</button>
						<!-- #endif -->

						<!-- #ifndef MP -->
						<image style="width: 120rpx;height: 120rpx;border-radius: 50%;"
							:src="info.s_thumb?info.s_thumb:base.erweima" mode="scaleToFill">
						</image>
						<!-- #endif -->
						<view class="gui-list-body">
							<view class="gui-list-title">
								<text class="gui-list-title-text gui-color-white">{{info.s_name}}</text>
								<!-- <text @click="setting"
									class="gui-icons gui-block gui-color-white gui-text gui-padding-x"
									style="font-size: 40rpx;">&#xe613;</text> -->

								<!-- <navigator url="/hyb_o2o/shouce/index/index?type=sj">
									<text class="gui-icons gui-block gui-text gui-padding-x"
										style="font-size: 30rpx;color:#ffffff;">操作手册&#xe601;</text>
								</navigator> -->

							</view>



							<view class="gui-color-white gui-text-small gui-margin-top2" v-if="info.ruzhu_endtime">
								认证:{{info.ruzhu_endtime.substring(0,10)}}
							</view>
						</view>
					</view>
				</view>

				<view @tap="scan()" v-if="base.show_base.sj_smhx"
					class="gui-margin-top-middle gui-margin-x-middle gui-bg-white gui-border-radius-large">
					<view class="gui-list  gui-border-b">
						<view class="gui-padding-middle gui-list-items">
							<text class="gui-list-icon gui-icons "
								style="font-size: 40rpx;color: #c2c2c2;">&#xe631;</text>
							<view class="gui-list-body">
								<view class="gui-list-title">
									<view class="gui-flex gui-align-items-center">
										<text class="gui-list-title-text">扫码核销</text>
									</view>

								</view>
							</view>
							<text class="gui-list-arrow-right gui-icons gui-color-gray">&#xe601;</text>
						</view>
					</view>
				</view>

				<hyb-popup-input ref="hexiao"></hyb-popup-input>




				<view class="gui-margin-top-middle gui-margin-x-middle gui-bg-white gui-border-radius-large">




					<navigator v-if="base.show_base.sj_fwdd" url="/hyb_o2o/inner/pages/fabu/list?tag=sj">
						<view class="gui-list  gui-border-b">
							<view class="gui-padding-middle gui-list-items">
								<text class="gui-list-icon gui-icons "
									style="font-size: 40rpx;color: #c2c2c2;">&#xe62f;</text>
								<view class="gui-list-body">
									<view class="gui-list-title">
										<view class="gui-flex gui-align-items-center">
											<text class="gui-list-title-text">服务订单</text>
										</view>

									</view>
								</view>
								<text class="gui-list-arrow-right gui-icons gui-color-gray">&#xe601;</text>
							</view>
						</view>
					</navigator>
					<navigator v-if="base.show_base.sj_spdd" url="/hyb_o2o/subpagesA/pages/order/order?tag=sj">
						<view class="gui-list  gui-border-b">
							<view class="gui-padding-middle gui-list-items">
								<text class="gui-list-icon gui-icons "
									style="font-size: 40rpx;color: #c2c2c2;">&#xe62f;</text>
								<view class="gui-list-body">
									<view class="gui-list-title">
										<view class="gui-flex gui-align-items-center">
											<text class="gui-list-title-text">商品订单</text>
										</view>

									</view>
								</view>
								<text class="gui-list-arrow-right gui-icons gui-color-gray">&#xe601;</text>
							</view>
						</view>
					</navigator>


					<navigator v-if="base.show_base.sj_fwdd" url="/hyb_o2o/jishi/list/list?juese=sj">
						<view class="gui-list  gui-border-b">
							<view class="gui-padding-middle gui-list-items">
								<text class="gui-list-icon gui-icons "
									style="font-size: 40rpx;color: #c2c2c2;">&#xe611;</text>
								<view class="gui-list-body">
									<view class="gui-list-title">
										<view class="gui-flex gui-align-items-center">
											<text class="gui-list-title-text">员工管理</text>
										</view>

									</view>
								</view>
								<text class="gui-list-arrow-right gui-icons gui-color-gray">&#xe601;</text>
							</view>
						</view>
					</navigator>

					<navigator v-if="this.$store.state.base.kefu_flag == 2" url="/hyb_o2o/kefunew/user_list?tag=yh">
						<view class="gui-list  gui-border-b">
							<view class="gui-padding-middle gui-list-items">
								<text class="gui-list-icon gui-icons "
									style="font-size: 40rpx;color: #c2c2c2;">&#xe626;</text>
								<view class="gui-list-body">
									<view class="gui-list-title">
										<view class="gui-flex gui-align-items-center">
											<text class="gui-list-title-text">客服消息</text>
										</view>

									</view>
								</view>
								<text class="gui-list-arrow-right gui-icons gui-color-gray">&#xe601;</text>
							</view>
						</view>
					</navigator>

					<navigator v-if="base.show_base.sj_fwdd" url="/hyb_o2o/shangjia/huiyuan/huiyuan">
						<view class="gui-list  gui-border-b">
							<view class="gui-padding-middle gui-list-items">
								<text class="gui-list-icon gui-icons "
									style="font-size: 40rpx;color: #c2c2c2;">&#xe612;</text>
								<view class="gui-list-body">
									<view class="gui-list-title">
										<view class="gui-flex gui-align-items-center">
											<text class="gui-list-title-text">购买会员</text>
										</view>

									</view>
								</view>
								<text class="gui-list-arrow-right gui-icons gui-color-gray">&#xe601;</text>
							</view>
						</view>
					</navigator>

					<!-- <navigator url="/hyb_o2o/inner/pages/balance/balance?tag=sj" v-if="$store.state.base.yu_e">
						<view class="gui-list gui-border-b">
							<view class="gui-padding-middle gui-list-items">
								<text class="gui-list-icon gui-icons  "
									style="font-size: 40rpx;color: #c2c2c2;">&#xe614;</text>
								<view class="gui-list-body">
									<view class="gui-list-title">
										<view class="gui-flex gui-align-items-center">
											<text class="gui-list-title-text">资金明细</text>
										</view>

									</view>
								</view>
								<text class="gui-list-arrow-right gui-icons gui-color-gray">&#xe601;</text>
							</view>
						</view>
					</navigator> -->

					<!-- <navigator url="/hyb_o2o/fenyong/fenyong?tag=sj">
						<view class="gui-list gui-border-b">
							<view class="gui-padding-middle gui-list-items">
								<text class="gui-list-icon gui-icons "
									style="font-size: 40rpx;color: #c2c2c2;">&#xe614;</text>
								<view class="gui-list-body">
									<view class="gui-list-title">
										<view class="gui-flex gui-align-items-center">
											<text class="gui-list-title-text">分佣明细</text>
										</view>

									</view>
								</view>
								<text class="gui-list-arrow-right gui-icons gui-color-gray">&#xe601;</text>
							</view>
						</view>
					</navigator> -->

					<navigator>
						<view v-if="base.show_base.sj_bao_zheng_jin"
							class="gui-padding-middle gui-list-items  gui-border-b" @tap="bzj">
							<text class="gui-list-icon gui-icons "
								style="font-size: 40rpx;color: #c2c2c2;">&#xe687;</text>
							<view class="gui-list-body ">
								<view class="gui-list-title">
									<view class="gui-flex gui-align-items-center">
										<text class="gui-list-title-text">保证金</text>
										<text v-if="info.baozhengjin > 0"
											class="gui-text-small  gui-margin-x gui-color-gray">￥
											{{info.baozhengjin}}</text>
										<text v-else class="gui-text-small  gui-margin-x gui-color-gray">￥0.00</text>


									</view>

								</view>
							</view>
							<text class="gui-list-arrow-right gui-icons gui-color-gray">&#xe601;</text>
						</view>
					</navigator>
					<view class="gui-list ">
						<view class="gui-list-items  gui-padding-middle gui-padding-y-middle gui-border-b">
							<text class="gui-list-icon gui-icons "
								style="font-size: 40rpx;color: #c2c2c2;">&#xe612;</text>
							<view class="gui-list-body ">
								<view class="gui-list-title">
									<view class="gui-flex gui-align-items-center">
										<text class="gui-list-title-text">我的钱包</text>
										<text
											class="gui-text-small  gui-margin-x gui-color-gray">￥{{info.s_money}}</text>
									</view>

								</view>
							</view>
							<button type="default" @tap="ti_xian()" :style="{'background':base.qjcolor}"
								style="transform:scale(0.9)" class="gui-button gui-noborder">
								<text class="gui-color-white gui-button-text gui-text-small">提现</text>
							</button>
						</view>
					</view>

				</view>


				<!-- 	<view v-if="base.show_base.bao_zheng_jin > 0  "
					class="gui-list gui-margin-top gui-bg-white gui-padding gui-margin-x">
					<view class="gui-list-items" @tap="bzj">
						<text class="gui-list-icon gui-icons gui-color-blue">&#xe687;</text>
						<view class="gui-list-body">
							<view class="gui-list-title">
								<view class="gui-flex gui-align-items-center">
									<text class="gui-list-title-text">保证金</text>
									<text class="gui-text-small gui-color-red gui-margin-x">￥{{info.baozhengjin}}</text>
								</view>

							</view>
						</view>


						<text class="gui-list-arrow-right gui-icons gui-color-red">&#xe601;</text>
					</view>
				</view> -->

				<!-- 
                <navigator v-if="this.$store.state.base.kefu_flag == 2" url="/hyb_o2o/kefunew/user_list?tag=yh" >
					<view class="gui-list gui-margin-top gui-bg-white gui-padding gui-margin-x">
						<view class="gui-list-items">
							<text class="gui-list-icon gui-icons gui-color-red">&#xe626;</text>
							<view class="gui-list-body">
								<view class="gui-list-title">
									<view class="gui-flex gui-align-items-center">
										<text class="gui-list-title-text">客服消息</text>
									</view>

								</view>
							</view>
							<text class="gui-list-arrow-right gui-icons gui-color-red">&#xe601;</text>
						</view>
					</view>
				</navigator> -->
				<!-- 	<navigator url="/hyb_o2o/shangjia/huiyuan/huiyuan">
					<view class="gui-list gui-margin-top gui-bg-white gui-padding gui-margin-x">
						<view class="gui-list-items">
							<text class="gui-list-icon gui-icons gui-color-red">&#xe6cf;</text>
							<view class="gui-list-body">
								<view class="gui-list-title">
									<view class="gui-flex gui-align-items-center">
										<text class="gui-list-title-text">购买会员</text>
									</view>

								</view>
							</view>
							<text class="gui-list-arrow-right gui-icons gui-color-red">&#xe601;</text>
						</view>
					</view>
				</navigator> -->
				<!-- 	<navigator url="/hyb_o2o/inner/pages/fabu/list?tag=sj">
					<view class="gui-list gui-margin-top gui-bg-white gui-padding gui-margin-x">
						<view class="gui-list-items">
							<text class="gui-list-icon gui-icons gui-color-red">&#xe6cf;</text>
							<view class="gui-list-body">
								<view class="gui-list-title">
									<view class="gui-flex gui-align-items-center">
										<text class="gui-list-title-text">我的接单</text>
									</view>

								</view>
							</view>
							<text class="gui-list-arrow-right gui-icons gui-color-red">&#xe601;</text>
						</view>
					</view>
				</navigator> -->
				<!-- 	<navigator url="/hyb_o2o/xqdt/xqdt?tag=xqdt">
					<view class="gui-list gui-margin-top gui-bg-white gui-padding gui-margin-x">
						<view class="gui-list-items">
							<text class="gui-list-icon gui-icons gui-color-red">&#xe6cf;</text>
							<view class="gui-list-body">
								<view class="gui-list-title">
									<view class="gui-flex gui-align-items-center">
										<text class="gui-list-title-text">抢单大厅</text>
									</view>

								</view>
							</view>
							<text class="gui-list-arrow-right gui-icons gui-color-red">&#xe601;</text>
						</view>
					</view>
				</navigator> -->

				<!-- 	<navigator url="/hyb_o2o/fenyong/fenyong?tag=sj">
					<view class="gui-list gui-margin-top gui-bg-white gui-padding gui-margin-x">
						<view class="gui-list-items">
							<text class="gui-list-icon gui-icons gui-color-red">&#xe6cf;</text>
							<view class="gui-list-body">
								<view class="gui-list-title">
									<view class="gui-flex gui-align-items-center">
										<text class="gui-list-title-text">分佣明细</text>
									</view>

								</view>
							</view>
							<text class="gui-list-arrow-right gui-icons gui-color-red">&#xe601;</text>
						</view>
					</view>
				</navigator> -->
				<!-- <navigator url="/hyb_o2o/shangjia/center/center">
					<view class="gui-list gui-margin-top gui-bg-white gui-padding gui-margin-x">
						<view class="gui-list-items">
							<text class="gui-list-icon gui-icons gui-color-red">&#xe6cf;</text>
							<view class="gui-list-body">
								<view class="gui-list-title">
									<view class="gui-flex gui-align-items-center">
										<text class="gui-list-title-text">工作台</text>
									</view>
				
								</view>
							</view>
							<text class="gui-list-arrow-right gui-icons gui-color-red">&#xe601;</text>
						</view>
					</view>
				</navigator> -->

			</view>
			<!-- <hyb-bzj tag="sj" ref="bzj"></hyb-bzj> -->
			<!-- <gui-modal ref="popup" :customClass="['gui-bg-white', 'gui-dark-bg-level-3', 'gui-border-radius']"
				title="注销验证码">
				<template v-slot:content>
					<view class="gui-flex gui-space-between gui-align-items-center gui-padding-x">
						<view class="gui-margin gui-bg-gray gui-border-radius" style="padding: 16rpx 20rpx;">
							<input v-model="code" type="number" placeholder="请输入验证码" />
						</view>
						<view v-if="time==0" class="gui-bg-red gui-color-white gui-text gui-flex-shrink0"
							style="padding: 20rpx 20rpx;">重新发送</view>
						<view v-else class="gui-bg-gray gui-color-black gui-text gui-flex-shrink0"
							style="padding: 20rpx 20rpx;">{{time}}s</view>
					</view>

				</template>

				利用 flex 布局 可以放置多个自定义按钮哦 
				<template v-slot:btns>
					<view class="gui-padding">
						<button type="default" @tap="comfirm" class="gui-button-mini  gui-bg-red gui-color-white">
							确认
						</button>
					</view>
				</template>
			</gui-modal> -->
		</template>
	</hyb-page>
</template>
<script>
	export default {
		data() {
			return {
				info: {},
				code: "",
				time: 0,
			}
		},
		computed: {
			base: () => {
				return uni.storage.get("base");
			}
		},

		onShow() {
			uni.gPost("shangjia/info", {
				is_rz: 1
			}).then((info) => {
				if (info) {
					if (info.s_status == "待审核") {
						uni.showModal({
							title: "商家提醒",
							content: "申请还在审核中，请稍候再来...",
							showCancel: false,
							success: (res) => {
								if (res.confirm) {
									uni.redirectTo({
										url: this.$store.state.base.hyzx_luj
									})
								}
							}
						})
					} else if (info.s_status == "未通过") {
						uni.showModal({
							title: "入驻提示",
							content: "您申请未通过,是否重新入驻?",
							success: (res) => {
								if (res.confirm) {
									uni.navigateTo({
										url: "/hyb_o2o/shangjia/ruzhu/ruzhu"
									})
								} else {
									uni.redirectTo({
										url: this.$store.state.base.hyzx_luj
									})
								}
							}
						})
					} else {
						this.info = info;
					}
				} else {
					uni.showModal({
						title: "入驻提示",
						content: "您还不是商家,是否现在入驻?",
						success: (res) => {
							if (res.confirm) {
								uni.navigateTo({
									url: "/hyb_o2o/shangjia/ruzhu/ruzhu?rz_type=1"
								})
							} else {
								uni.redirectTo({
									url: this.$store.state.base.hyzx_luj
								})
							}
						}
					})
				}
			})
		},

		methods: {
			scan() {
				uni.scanCode({
					success: (res) => {
						const code = res.result
						if (code.startsWith('goods_')) {
							// 显示确认对话框
							const out_trade_no = code.replace('goods_', '')
							uni.showModal({
								title: "确认核销",
								content: `确定核销订单：${out_trade_no}吗?`,
								success: (confirmRes) => {
									if (confirmRes.confirm) {
										uni.gPost(
											'goods/order/hexiao', {
												out_trade_no: out_trade_no
											}).then(res => {
											// 使用模态框显示核销成功提示，与积分核销保持一致
											uni.showModal({
												title: "核销成功",
												content: `订单 ${out_trade_no} 核销成功！`,
												showCancel: false,
												success: (res) => {
													if (res.confirm) {
														// 刷新页面数据
														this.onShow();
													}
												}
											})
										}).catch(err => {
											uni.showToast({
												title: err
													.message ||
													'核销失败',
												icon: 'none'
											})
										})
									}
								}
							})
						} else {
							uni.showModal({
								editable: true,
								title: '请输入核销积分',
								placeholder: '请输入要扣除的积分数量',
								success: (res) => {
									const jifen = Number(res.content)
									if (isNaN(jifen) || jifen < 0) {
										uni.showToast({
											title: '积分输入错误',
											icon: 'none'
										})
									} else {
										// 显示确认对话框
										uni.showModal({
											title: "确认核销",
											content: `确定要扣除用户 ${jifen} 积分吗？`,
											success: (confirmRes) => {
												if (confirmRes.confirm) {
													uni.gPost(
														'shangjia/jifen/hexiao', {
															code: code,
															jifen: jifen
														}).then(res => {
														// 使用模态框显示核销成功提示
														uni.showModal({
															title: "核销成功",
															content: `成功扣除用户 ${jifen} 积分，已转入您的积分账户`,
															showCancel: false,
															success: (
																res
															) => {
																if (res
																	.confirm
																) {
																	// 刷新页面数据
																	this
																		.onShow();
																}
															}
														})
													}).catch(err => {
														uni.showToast({
															title: err
																.message ||
																'核销失败',
															icon: 'none'
														})
													})
												}
											}
										})
									}
								}
							})
						}
					}
				})
			},

			location() {

				uni.location.getLocation().then((location) => {
					if (location) {
						uni.gPost('shangjia/save', {
							latitude: location.latitude,
							longitude: location.longitude
						}).then(res => {
							uni.showToast({
								title: '更新成功',
								icon: 'none'
							})
						})
					} else {
						uni.showToast({
							title: '定位失败',
							icon: 'none'
						})
					}
				})
			},


			bzj() {
				if (this.info.baozhengjin > 0) {
					var itm_a = ["充值", "提现"];
				} else {
					var itm_a = ["充值"];
				}
				uni.showActionSheet({
					itemList: itm_a,
					success: (res) => {
						if (res.tapIndex == 1) {
							// uni.navigateTo({
							// 	url: "/hyb_o2o/tixian/tixian?tag=sj_bzj"
							// })
						} else if (res.tapIndex == 0) {
							this.recharge();
						}
					}
				})
			},

			// comfirm() {
			// 	if (this.code.length != 4) {
			// 		uni.showToast({
			// 			title: "验证码错误!",
			// 			icon: 'none'
			// 		})
			// 	} else {
			// 		uni.gPost("yuangong/remove").then(() => {
			// 			this.$refs.popup.close();
			// 			uni.redirectTo({
			// 				url: this.$store.state.base.hyzx_luj
			// 			})
			// 		})
			// 	}
			// },

			// setting() {
			// 	uni.showActionSheet({
			// 		itemList: ["注销帐户"],
			// 		success: (res) => {
			// 			if (res.tapIndex == 0) {
			// 				uni.showModal({
			// 					title: "注销提醒",
			// 					content: "注销后将消除所信信息，是否确认操作?",
			// 					success: (res) => {
			// 						if (res.confirm) {
			// 							uni.gPost("yuangong/zx/sms").then(() => {
			// 								this.time = 120;
			// 								this.timer();
			// 								this.$refs.popup.open();
			// 							})
			// 						}
			// 					}
			// 				})
			// 			}
			// 		}
			// 	})
			// },


			// timer() {
			// 	if (this.time > 0) {
			// 		this.time--;
			// 		setTimeout(() => {
			// 			this.timer();
			// 		}, 1000)
			// 	}
			// },

			recharge() {
				this.$refs.bzj.open();
			},

			ti_xian() {
				// uni.navigateTo({
				// 	url: "/hyb_o2o/tixian/tixian?tag=sj"
				// })

			},

			// ti_xian() {
			// 	uni.showModal({
			// 		title: "提现",
			// 		content: "确定提现？",
			// 		success: (res1) => {
			// 			if (res1.confirm) {
			// 				uni.gPost("yuangong/bzj_st", {
			// 					s_id: this.info.s_id,
			// 					baozhengjin: this.info.baozhengjin
			// 				}).then((info) => {
			// 					this.info = info;
			// 				})
			// 			}
			// 		}
			// 	})
			// },

			// jdChange(e) {
			// 	uni.gPost("yuangong/save", {
			// 		s_id: this.info.s_id,
			// 		jd_tongzhi: e.detail.value ? 1 : 0
			// 	}).then((res) => {
			// 		uni.gJs.msg("操作成功!")
			// 	})
			// },
			// to(url) {
			// 	uni.gJs.navigate(url);
			// },
			// yg_huiyuan() {
			// 	uni.navigateTo({
			// 		url: "/hyb_o2o/xqdt/xqdt"
			// 	})
			// },
			// toInfo() {
			// 	uni.gJs.navigate("/hyb_o2o/user/info/info");
			// },

		}
	}
</script>
<style scoped>
	.gui-button {
		padding: 0 40rpx !important;
		height: 60rpx;
		padding: 0;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.gui-ic-image {
		width: 68rpx;
		height: 68rpx;
		margin-bottom: 10rpx;
	}

	.avatar-wrapper {
		background: none;
		padding: 0;
		border: none;
	}

	.avatar-wrapper::after {
		border: none;
	}
</style>